{#include file="top_r.php"#}
<script charset="utf-8" src="/js/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/js/kindeditor/lang/zh_TW.js"></script>
<script type="text/javascript">
    function showpop(text) {
        $("#dialog").fadeOut('slow');
        showLB('#dialog_popup', 0);
        $("#popupText").text(text);
    }

    function showdialog(text) {
        $("#dialog_popup").fadeOut('slow');
        showLB('#dialog', 0);
        $("#dialogText").text(text);
    }

    function callback(content) {
        switch (content['retcode']) {
            case 4:
                showdialog("你的 Blog 文章已成功保存，可於會員中心編輯或發佈。");
                break;
            case 1:
                showdialog("你的 Blog 文章已成功發佈！");
                break;
            case 2:
                $('#mark1').html('<span class="sp_pink">x</span> 標題不能為空');
                //showpop(content['msg']);
                window.scrollTo(0, 0);
                break;
            case 3:
                $('#mark4').html('<span class="sp_pink">x</span> 內容不能為空');
                //showpop(content['msg']);
                window.scrollTo(0, 0);
                break;
            default:
                showpop(content['msg']);
                break;
        }
    }

    function pempty(s) {
        $('#' + s).html('&nbsp;');
    }

    function showLB(ct, n) {
        var sh = $(document).height();
        var sw = $(document).width();
        var st = $(window).scrollTop();
        var ch = $(window).height();
        var cw = $(window).width();
        var tbT = (Number(ch) / 3 + Number(st)) + "px";
        var tbL = (Number(cw) / 2) + "px";
        if (n == 0) {
            $("#fullbg").css({width: sw, height: sh});
            $(ct).css({top: tbT, left: tbL});
            $("#fullbg").fadeTo('slow', 0.4);
            $(ct).fadeIn('slow');
            $(window).scroll(function() {
                showLB(ct, 1)
            });
            $(window).resize(function() {
                showLB(ct, 1)
            });
        } else {
            if ($("#fullbg").css("display") == "block") {
                $("#fullbg").css({width: sw, height: sh});
                $(ct).css({top: tbT, left: tbL});
            }
        }
    }

    function closeLB(ct) {
        $(ct).fadeOut('slow');
        $("#fullbg").fadeOut('slow');
    }

    function s_t(s) {
        var c = $('[' + s + '=1]');
        if (parseInt(c.attr('v')) == 0) {
            c.show();
            c.attr('v', 1);
        } else {
            c.hide();
            c.attr('v', 0);
        }
    }

    function s_c(t, s, f) {
        $('#' + f).val($(t).attr('v'));
        $('[' + s + '=0]').html($(t).html());
        $('[' + s + '=1]').hide();
        $('[' + s + '=1]').attr('v', 0);
    }

    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('textarea[name="content"]', {
            resizeType: 1,
            height: 300,
            autoHeightMode: true,
            afterBlur: function() {
                this.sync();
            },
            langType: 'zh_TW',
            allowPreviewEmoticons: false,
            allowImageUpload: true,
            items: [
                'undo', 'redo', 'preview', 'selectall', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                'removeformat', '|', 'emoticons', 'image', 'multiimage', 'fullscreen']
        });
    });

    function ireset() {
        $('.p_text_s').html('');
        $('#title').val('');
        $('#age_txt').html('{#$agegroup.result.0.cname#}');
        $('#age').val('1');
        $('#skin_txt').html('{#$face_skin.result.0.cname#}');
        $('#skin').val('1');
        $('[s="well"]').removeAttr("checked");
        $('[s="star"]').removeClass();
        $('[s="star"]').addClass('star star_0');
        $('[s="score"]').val('0');
        $('#content').val('');
        editor.html('');
    }

    function other_conf(t) {
        var item = $('#hide_item');
        item.toggle(0, function() {
            if (item.is(':hidden')) {
                $(t).removeClass('tri_down').addClass('tri_up');
            } else {
                $(t).removeClass('tri_up').addClass('tri_down');
            }
        });
    }

    function new_catefory() {
        var name = $.trim($('#new_catefory_name').val());
        var topid = $('#new_category_list').val();
        if (name == '')
            return;
        $.getJSON("/member_center.php?action=blog_do&do=5", {name: name, topid: topid}, function(data) {
            if (parseInt(data.recode) == 1) {
                var bls_i = topid!=0 ? (parseInt($("#cfbl_" + topid).attr('s')) + 1) : 0;
                var bls_s = bls_i * 20;
                var bls = '';
                for (var i = bls_i; i > 0; i--) {
                    bls = bls + '　'
                }
                ;
                var ss1 = '<div style="font-size:15px;margin-left:' + bls_s + 'px" id="cfbl_' + data.id + '" s="' + bls_i + '"><input class="ipt_cb" type="checkbox" name="catefory_box[]" value="' + data.id + '" /><span id="blog_c_name_' + data.id + '" onclick="input_text(1,' + data.id + ')">' + name + '</span><span id="blog_c_name_input_' + data.id + '" style="display:none;"><input type="text" id="bci_' + data.id + '" name="bci_' + data.id + '" value="' + name + '" maxlength="30" onblur="input_text(2,' + data.id + ')"/></span><a href="javascript:void(0);" id="cd_' + data.id + '" onclick="cate_del(' + data.id + ')" >×</a></div>';
                var ss2 = '<option id="new_category_list_option_' + data.id + '" value="' + data.id + '">' + bls + name + '</option>';
                if (topid != 0) {
                    $('#cfbl_' + topid).after(ss1);
                    $('#new_category_list_option_' + topid).after(ss2);
                } else {
                    $('#catefory_box').append(ss1);
                    $('#new_category_list').append(ss2);
                }
            }
        });
        $('#new_catefory_name').val('');
    }

    function cate_del(cid) {
        $.getJSON("/member_center.php?action=blog_do&do=7", {id: cid}, function(data) {
            if (parseInt(data.recode) == 1) {
                $('#cfbl_' + cid).remove();
                $('#new_category_list_option_' + cid).remove();
            } else {
                showpop(data.msg);
            }
        });
    }

    function input_text(i, cid) {
        if (i == 1) {
            $('#blog_c_name_' + cid).hide();
            $('#blog_c_name_input_' + cid).show();
            $('#bci_' + cid).focus();
        } else {
            var name = $.trim($('#bci_' + cid).val());
            if (name == '') {
                $('#blog_c_name_' + cid).show();
                $('#blog_c_name_input_' + cid).hide();
            }
            $.getJSON("/member_center.php?action=blog_do&do=6", {name: name, id: cid}, function(data) {
                if (parseInt(data.recode) == 1) {
                    $('#blog_c_name_' + cid).html(name).show();
                    $('#blog_c_name_input_' + cid).hide();
                    $('#bci_' + cid).val(name);
                } else {
                    $('#blog_c_name_' + cid).show();
                    $('#blog_c_name_input_' + cid).hide();
                }
            });

        }
    }

</script>
<form action='/member_center.php?action=blog_add' method='post' target='iframe11' name='form1' id='form1'>
    <div class="body">
        <div class="pro_detail_box pro_detail_box_try_r b_box">
            <div class="hd">
                <h2 class="hd_title blog_title"/>編寫blog </h2>
            </div>
            <div class="bd">
                <input type='hidden' name='issubmit' value='1' />
                <input type='hidden' name='do' value='{#$do#}' />
                <input type='hidden' name='bid' value='{#$bid#}' />
                <div class="part_4">
                    <!--
					<div class="details_box">
                        <span class="span_l">品牌分類</span>
                        <a class="btn_s btn_s_csort" href="javascript:void(0);" onclick="$('#dialog_category_list').show();"><strong>選擇分類</strong></a>
                    </div>
					-->
                    <span class="n_title">標題</span>
                    <input type="text" class="ipt_title" name="title" id="title" onfocus="pempty('mark1')" value="{#htmlspecialchars_decode($my_blogs.result.0.title)#}"  maxlength="80"/>
                    <span class="p_text_s" id='mark1'>&nbsp;</span>

                    <a class="optional">高級選項<i class="tri tri_up" onclick="other_conf(this);" ></i></a>

                    <div id="hide_item" class="part_2 optional_div" style="display: none">
                        <div class="details_box details_box_1 details_box_z1">
                            <span class="span_l">年齡</span>
                            <div class="droplist_box">
                                <a id='age_txt' class="choose" href="javascript:void(0);" c1=0 onclick="s_t('c1')">{#if !empty($my_blogs.result.0.agegroup)#}{#$agegroup['result'][$my_blogs.result.0.agegroup-1]['cname']#}{#else#}{#$agegroup.result.0.cname#}{#/if#}</a>
                                <ul class="drop_list drop_list_1" c1=1 v=0 style='display:none'>
                                    {#foreach  from=$agegroup.result item=v key=k#}
                                    <li v='{#$v.id#}' style='cursor:pointer;' onclick="s_c(this, 'c1', 'age')">{#$v.cname#}</li>
                                    {#/foreach#}
                                </ul>
                                <input type='hidden' name='age' id='age' value='{#if !empty($my_blogs.result.0.agegroup)#}{#$my_blogs.result.0.agegroup#}{#else#}0{#/if#}' />

                            </div>
                            <!--<span class="span_sp">臉部膚質</span>
                            <div class="droplist_box">
                                <a id='skin_txt' class="choose" href="javascript:void(0);" c2=0 onclick="s_t('c2')">{#if !empty($my_blogs.result.0.body_skin_id)#}{#$face_skin['result'][$my_blogs.result.0.body_skin_id-1]['cname']#}{#else#}{#$face_skin.result.0.cname#}{#/if#}</a>
                                <ul class="drop_list drop_list_2" c2=1 v=0 style='display:none;left:330px'>
                                    {#foreach  from=$face_skin.result item=v key=k#}
                                    <li v='{#$v.id#}' style='cursor:pointer;' onclick="s_c(this, 'c2', 'skin')">{#$v.cname#}</li>
                                    {#/foreach#}
                                </ul>
                                <input type='hidden' name='skin' id='skin' value='{#if !empty($my_blogs.result.0.body_skin_id)#}{#$my_blogs.result.0.body_skin_id#}{#else#}0{#/if#}' />
                            </div>
							-->
                        </div>
                        <div class="details_box details_box_1 details_box_z2">
                            <span class="span_l">產品整體滿意度</span>
                            {#foreach  from=$product_reports_well.result item=v key=k#}
                            <input type='radio' class="ipt_radio" s="well" id="est{#$k+1#}" name='well' value='{#$v.id#}'  {#if $my_blogs.result.0.well == $v.id#}checked{#/if#}/><label for="">{#$v.cname#}</label>
                            {#/foreach#}
                        </div>
                        <div class="details_box details_box_last">
                            <span class="span_l">產品功能評分</span>
                            <div class="star_box">
                                <table>
                                    <tr>
                                        {#foreach  from=$vote_option_data.result item=v key=k#}
                                        <th>{#$v#}</th>
                                        <td><div class="star {#if !empty($my_blogs['result'][0]['category_score'|cat:($k+1)])#}star_{#$my_blogs['result'][0]['category_score'|cat:($k+1)]#}{#else#}star_0{#/if#}" s='star' id="star_{#$k+1#}">
                                                {#foreach  from=array(1,2,3,4,5) item=v1 key=k1#}
                                                <a class="s{#$v1#}" href="javascript:void(0);" v="{#$v1#}" onclick="$('#category_score{#$k+1#}').val($(this).attr('v'));
        $('#star_{#$k+1#}').removeClass();
        $('#star_{#$k+1#}').addClass('star star_' + $(this).attr('v'));">{#$v#}分</a>
                                                {#/foreach#}
                                                <input type='hidden' s='score' name='category_score{#$k+1#}' id="category_score{#$k+1#}" value="{#if !empty($my_blogs['result'][0]['category_score'|cat:($k+1)])#}{#$my_blogs['result'][0]['category_score'|cat:($k+1)]#}{#else#}0{#/if#}" />
                                            </div></td>
                                        {#if ($k+1)%3 eq 0#}</tr><tr>{#/if#}
                                        {#/foreach#}
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div style="width:100%;padding:10px 3% 10px 3%;">
                        <textarea name="content" id="content" style="width:94%;height:200px;visibility:hidden;">{#htmlspecialchars_decode($my_blogs.result.0.body)#}</textarea>
                        <p class="p_text_s" style='margin-bottom:12px;' id='mark4'>&nbsp;</p>
                    </div>
                </div>
                <br/>
                <div class="button_box bb_btn_4">
                    <a class="btn_box btn_r_box" href="javascript:void(0);" onclick="$('#form1').attr('action', '/member_center.php?action=blog_do').attr('target', 'iframe1').submit();">遞交</a>
                    <a class="btn_box btn_b_box" href="javascript:void(0);" onclick="ireset();">重設</a>
                    <a class="btn_box btn_r_box" href="javascript:void(0);" onclick="$('#form1').attr('action', '/person.php?action=blog&username={#$memberData.username#}&p=1').attr('target', '_blank').submit();">預覽</a>
                    <a class="btn_box btn_b_box" href="javascript:void(0);" onclick="$('#form1').attr('action', '/member_center.php?action=blog_do&p=0').attr('target', 'iframe1').submit();">存為草稿</a>
                </div>
            </div>
            <div class="ft"></div>
        </div>

    </div><!--body-->
    <div class="popup sort_popup"  id="dialog_category_list"  style="display:none;">
        <a class="btn_close" href="javascript:void(0);" onclick="closeLB('#dialog_category_list');" ></a>
        <div class="alert_box b_box">
            <div class="hd">
                <h2 class="title">選擇分類</h2>
            </div>
            <div class="bd">
                <div id="catefory_box">
                    {#foreach  from=$blog_category_list item=v key=k#}
                    <div style="font-size:15px;margin-left:{#($bls_n.$k)*20#}px" id="cfbl_{#$k#}" s="{#$bls_n.$k#}">
                        <input class="ipt_cb" type="checkbox" name="catefory_box[]" value="{#$k#}" {#if in_array($k,$blog_category_checked)#}checked{#/if#}/><span id='blog_c_name_{#$k#}' onclick="input_text(1, {#$k#})">{#$v#}</span>
                        <span id='blog_c_name_input_{#$k#}' style="display:none;">
                            <input type="text" id="bci_{#$k#}" name="bci_{#$k#}" value="{#$v#}" maxlength="30" onblur="input_text(2, {#$k#})"/>
                        </span>
                        <a href="javascript:void(0);" id="cd_{#$k#}" onclick="cate_del({#$k#})" >×</a>
                    </div>
                    {#/foreach#}
                </div>

                <a class="btn_s btn_s_asort" href="javascript:void(0);" onclick="$('#dialog_category').show();"><strong>添加分類</strong></a>
            </div>
            <div class="ft">
                <a class="btn_box btn_r_box" href="javascript:void(0);" onclick="closeLB('#dialog_category_list');">確定</a>
                <a class="btn_box btn_b_box" href="javascript:void(0);" onclick="closeLB('#dialog_category_list');">取消</a>
            </div>
        </div>
    </div>

</form>

<div id="fullbg"></div>
<div id='dialog' class="popup popup_2" style="z-index: 60;	display:none;">
    <a class="btn_close" href='javascript:void(0);' onclick="closeLB('#dialog');
        window.location.href = '/member_center.php?action=blog';"></a>
    <div class="alert_box b_box">
        <div class="hd">
            <h2 class="hd_title">提示信息</h2>
        </div>
        <div class="bd">
            <p id="dialogText"></p>
            <a class="btn_b btn_b_return_blog" href="/member_center.php?action=blog"> <strong>回到iTrial Blog</strong></a>
        </div>
    </div>
</div>
<div style="top:400px;z-index:60;display:none;" class="apopbox popbox b_box" id="dialog_popup">
    <div class="hd">
        <h2 class="ir ht"><span>提示信息 ALERT</span></h2>
        <a class="popclose" onclick="closeLB('#dialog_popup');" style="cursor:pointer">close</a>            </div>
    <div class="bd">
        <p id="popupText"></p>
        <a class="btn_b btn_s_im_back" href="javascript:void(0);" onclick="closeLB('#dialog_popup');"><strong>立即返回</strong></a>
    </div>
</div>

<div class="popup sort_popup" style="display:none;" id="dialog_category">
    <a class="btn_close" href="javascript:void(0);" onclick="closeLB('#dialog_category');" ></a>
    <div class="alert_box b_box">
        <div class="hd">
            <h2 class="title">添加分類</h2>
        </div>
        <div class="bd">
            <table class="sort_tb">
                <tr>
                    <td>分類名字</td>
                    <td class="td_2">
                        <input type="text" class="sort_name" id="new_catefory_name" name="new_catefory_name" maxlength="30"/>
                    </td>
                    <td class="td_3">於</td>
                    <td>
                        <select id="new_category_list" name="new_category_list">
                            <option id="new_category_list_option_0" value="0">---top---</option>
                            {#foreach  from=$blog_category_list_n item=v key=k#}
                            <option id="new_category_list_option_{#$k#}" value="{#$k#}">{#$v#}</option>
                            {#/foreach#}
                        </select>
                    </td>
                </tr>
            </table>
        </div>
        <div class="ft">
            <a class="btn_box btn_r_box" href="javascript:void(0);" onclick="new_catefory();
        closeLB('#dialog_category');">確定</a>
            <a class="btn_box btn_b_box" href="javascript:void(0);" onclick="closeLB('#dialog_category');">取消</a>
        </div>
    </div>
</div>
<iframe id="iframe1" name="iframe1" style="display:none"></iframe>
</div>
</body>
</html>